<include file="Public:head" />
<link href="__APP__/Application/{$Think.MODULE_NAME}/Public/css/gifts.css" rel="stylesheet" type="text/css" />
<script>
    function getGifts(id,title,points){
        var div = "<div class='browsebox' id='browsebox' style='width:456px;'>\n\
    <div class='head' id='headbox'>\n\
        <a class='close' onclick=closebgbox('#mainbox')></a>\n\
        <span id='title'>积分兑换</span></div>\n\
<div class='boxcontent' style='padding:0'>\n\
<div class='clear_cart_inner'>\n\
<div class='cf_con'>\n\
<strong>您选择兑换的礼品为：</strong><span class=cf_tit>"+title+"</span>\n\
<p class=cf_p1>扣除：<span class=cf_money>"+points+"</span></p>\n\
<p>姓名：<input name=truename type=text></p>\n\
<p>电话：<input name=phone type=text style='margin:12px 0'></p>\n\
<p>地址：<textarea name=addr style='width:204px;'></textarea></p></div>\n\
<div class='do_clear_cart clearfix' style='padding:16px 30px 13px 0'>\n\
<a class='do_not_clear' onclick=getGiftsConfirm("+id+")>确认</a><a class='do_clear'  onclick=closebgbox('#mainbox')>取消</a>\n\
</div></div></div></div>";
            $('#mainbox').html(div);
            showbgbox('#browsebox',0,0);
            $('#clearcart').show();
    }
    function getGiftsConfirm(id){
        var truename = $("input[name=truename]").val();
        var phone = $("input[name=phone]").val();
        var addr = $("textarea[name=addr]").val();
        if(truename == ''){
            showTip('系统提示',"姓名不能为空！",'2',1.5,"input[name=truename]");
            return false;
        }
        if(phone == ''){
            showTip('系统提示',"电话不能为空！",'2',1.5);
            return false;
        }
        if(addr == ''){
            showTip('系统提示',"地址不能为空！",'2',1.5);
            return false;
        }
        $.post("{:U('Ajax/getGiftsConfirm')}",{
            id:id,
            phone:phone,
            truename:truename,
            addr:addr
        },function(data){
            if(data == -1){
                showTip('系统提示',"亲，您还没登陆！",'2',1.5);
            }else if(data == -2){
                showTip('系统提示',"亲，积分不够！",'2',1.5);
            }else{
                showTip('系统提示',"兑换礼品成功！",'2',1.5);
                closebgbox('#mainbox')
            }
            
        })
        
    }
    </script>
<div id="containter">
    <div id="wrap">
        <div id="school">
        {$type=0|getAreaName} 
        <a href="__APP__/?type=clean">[切换位置]</a>
        <span>/</span>
        <em>积分商城</em>
    </div>     
        <!--end of header-->
        <div id="container" class="clearfix">
            <div id="left" class="shadow gift">
                <div id="s_tab">
                    <h3>积分商城</h3>
                </div>
                <p class="gift-center">积分获取规则：订餐成功后，总积分=原有积分+订餐金额×10</p>
                 <ul class="clearfix">
                     <foreach name="cats" item="row">
                    <li>
                        <h2>{$row.name}</h2>
                        <dl>
                            <foreach name="row['sub']" item="row2">
                            <dd>
                                <img src="__APP__/{$Think.config.picFile}{$row2.pic}" alt="{$row2.title}"style='width:150px;height:150px;' /><p>{$row2.title}</p>
<!--                                <button >我要兑换</button>-->
                                <input type="button" value="我要兑换" onclick="getGifts('{$row2.id}','{$row2.title}','{$row2.points}')">
                            </dd>
                          </foreach>
                        </dl>
                    </li>
                    </foreach>
                </ul>
            </div>
            <!--end of left-->
            <div id="right">
                <div class="right_item shadow" id="goto_draw">
                    <div class="right_point_draw">
                        <img src="__APP__/Application/{$Think.MODULE_NAME}/Public/images/right_point_draw.png" alt=""/>
                        <h2>{$config.title}积分大抽奖</h2>
                        <p>还等什么？快来试试手气吧!</p>
                        <a href="{:U('Gifts/award')}" class="goto_draw">立刻去抽奖</a>
                    </div>
                </div>
            </div>
        </div>
        <include file="Public:foot" />